<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
if(isset($_REQUEST['submitBtn']))
{
  $partyName       = isset($_POST['partyName']) && ($_POST['partyName'] != "") ? $_POST['partyName'] : 0 ;
  $SelectPartyType = isset($_POST['SelectPartyType']) && ($_POST['SelectPartyType'] != "") ? $_POST['SelectPartyType'] : 0 ;
  $address        = isset($_POST['address']) && ($_POST['address'] != "") ? $_POST['address'] : 0 ;
  $address2        = isset($_POST['address2']) && ($_POST['address2'] != "") ? $_POST['address2'] : 0 ;
  $city            = isset($_POST['city']) && ($_POST['city'] != "") ? $_POST['city'] : 0 ;
  $city2            = isset($_POST['city2']) && ($_POST['city2'] != "") ? $_POST['city2'] : 0 ;
  $contact1        = isset($_POST['contact1']) && ($_POST['contact1'] != "") ? $_POST['contact1'] : 0 ;
  $contact2        = isset($_POST['contact2']) && ($_POST['address'] != "") ? $_POST['contact2'] : 0 ;
  $contact3        = isset($_POST['contact3']) && ($_POST['contact3'] != "") ? $_POST['contact3'] : 0 ;
  $contact4        = isset($_POST['contact4']) && ($_POST['contact4'] != "") ? $_POST['contact4'] : 0 ;
  $email           = isset($_POST['email']) && ($_POST['email'] != "") ? $_POST['email'] : 0 ;
  $email2          = isset($_POST['email2']) && ($_POST['email2'] != "") ? $_POST['email2'] : 0 ;
  $web             = isset($_POST['web']) && ($_POST['web'] != "") ? $_POST['web'] : 0 ;
  $fax1            = isset($_POST['fax1']) && ($_POST['fax1'] != "") ? $_POST['fax1'] : 0 ;
  $fax2            = isset($_POST['fax2']) && ($_POST['fax2'] != "") ? $_POST['fax2'] : 0 ;
  $assistant       = isset($_POST['assistant']) && ($_POST['assistant'] != "") ? $_POST['assistant'] : 0 ;
  $assistantNo     = isset($_POST['assistantNo']) && ($_POST['assistantNo'] != "") ? $_POST['assistantNo'] : 0 ;
  $assistantAdd    = isset($_POST['assistantAdd']) && ($_POST['assistantAdd'] != "") ? $_POST['assistantAdd'] : 0 ;
  	
 echo $insertItem = "INSERT INTO party (partyName,partyType,address,address2,city,city2,contact1,contact2,
                                    contact3,contact4,email,email2,web,fax1,fax2,assistant,assistantNo,assistantAdd)
                             VALUES('".$_POST['partyName']."',
                                    '".$_POST['SelectPartyType']."',
                                    '".$_POST['address']."',
                                    '".$_POST['address2']."',
                                    '".$_POST['city']."',
                                    '".$_POST['city2']."',
                                    '".$_POST['contact1']."',
                                    '".$_POST['contact2']."',
                                    '".$_POST['contact3']."',
                                    '".$_POST['contact4']."',
                                    '".$_POST['email']."',
                                    '".$_POST['email2']."',
                                    '".$_POST['web']."',
                                    ".$fax1.",
                                    ".$fax2.",
                                    '".$_POST['assistant']."',
                                    '".$_POST['assistantNo']."',
                                    '".$_POST['assistantAdd']."')";
    $insertItemRes = mysql_query($insertItem);
    if(!$insertItemRes)
    {
    	echo "INSERT FAIL";
    }
    else
    {
      header("Location:party.php");
    }
  }
  
  
  // Display All Record of Party
  $partyArray = array();
  $p = 0;
  $selectParty    = "SELECT partyId,partyName,partyType,address,address2,city,city2,contact1,contact2,
                            contact3,contact4,email,email2,web,fax1,
                            fax2,assistant,assistantNo,assistantAdd
                       FROM party
                      ORDER BY partyName";
  $selectPartyRes = mysql_query($selectParty);
   
  while($partyRows = mysql_fetch_array($selectPartyRes))
  {
  	$partyArray[$p]['partyId']       = $partyRows['partyId'];
    $partyArray[$p]['partyName']     = $partyRows['partyName'];
    $partyArray[$p]['partyType']     = $partyRows['partyType'];
    $partyArray[$p]['address']       = $partyRows['address'];
    $partyArray[$p]['address2']      = $partyRows['address2'];
    $partyArray[$p]['city']          = $partyRows['city'];
    $partyArray[$p]['city2']         = $partyRows['city2'];
    $partyArray[$p]['contact1']      = $partyRows['contact1'];
    $partyArray[$p]['contact2']      = $partyRows['contact2'];
    $partyArray[$p]['contact3']      = $partyRows['contact3'];
    $partyArray[$p]['contact4']      = $partyRows['contact4'];
    $partyArray[$p]['email']         = $partyRows['email'];
    $partyArray[$p]['email2']        = $partyRows['email2'];
    $partyArray[$p]['web']           = $partyRows['web'];
    $partyArray[$p]['fax1']          = $partyRows['fax1'];
    $partyArray[$p]['fax2']          = $partyRows['fax2'];
    $partyArray[$p]['assistant']     = $partyRows['assistant'];
    $partyArray[$p]['assistantNo']   = $partyRows['assistantNo'];
    $partyArray[$p]['assistantAdd']  = $partyRows['assistantAdd'];
    $p++;
  }
  include("./bottom.php");
  $smarty->assign("partyArray",$partyArray);
  $smarty->display("party.tpl");
?>

